<script setup lang="ts">
import $api from "@/api";

const showLogin = ref(false);
function setCookie() {
  window.electronAPI.setCookie({
    url: "https://api.live.bilibili.com/",
    name: "sid",
    value: "nxmck77b",
    domain: "bilibili.com",
    hostOnly: true,
    path: "/",
    secure: false,
    sameSite: "lax",
    expirationDate: 1712383883.07833
  });
}
function getCookie() {
  window.electronAPI
    .getCookie({
      domain: "bilibili.com"
    })
    .then(v => {
      console.log(v);
    });
}
function sendMsg() {
  $api.bili.sendDanmuMsg(25765444, "123456").then(res => {
    console.log(res);
  });
}
function clearCookie() {
  window.electronAPI.clearCookie("https://passport.bilibili.com").then(v => {
    console.log(v);
  });
}
function getUserInfo() {
  $api.bili.getBaseUserInfo().then(data => {
    console.log(data);
  });
}
function createWindow() {
  window.electronAPI.createWindow({}, "/").then(w => {
    console.log(w);
  });
}
function startBlive() {
  window.electronAPI.listenBlive(25765444).then(w => {
    console.log(w);
  });
}
function onDanmu(value) {
  console.log("Danmu:", value);
}
function addBliveEvent() {
  //window.electronAPI.addBliveEvent("Danmu", onDanmu);
  window.$bus.on("blive:Danmu", onDanmu);
}
function removeBliveEvent() {
  //window.electronAPI.removeBliveEvent("Danmu", onDanmu);
}
</script>

<template>
  <div>
    <n-button type="primary" @click="showLogin = true">Primary</n-button>
    <n-button type="primary" @click="setCookie">setCookie</n-button>
    <n-button type="primary" @click="getCookie">getCookie</n-button>
    <n-button type="primary" @click="clearCookie">clearCookie</n-button>
    <n-button type="primary" @click="sendMsg">发送</n-button>
    <n-button type="primary" @click="getUserInfo">用户信息</n-button>
    <n-button type="primary" @click="createWindow">createWindow</n-button>
    <n-button type="primary" @click="startBlive">startBlive</n-button>
    <n-button type="primary" @click="addBliveEvent">addBliveEvent</n-button>
    <n-button type="primary" @click="removeBliveEvent"
      >removeBliveEvent</n-button
    >
    <MLogin v-model:show="showLogin" />
  </div>
</template>

<style scoped lang="scss"></style>

<route>
{
  meta: {
    layout: "default"
  }
}
</route>
